package com.noble.glamour.bean.center.user.detail;

import android.os.Parcel;

import com.noble.library.log.PSP;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户详细信息
 */
public class UserDetail extends UserInfo {
    private List<UserPhoto> userPhotos = new ArrayList<>();
    private List<UserVideo> userVideos = new ArrayList<>();

    // 暂时无用
    private UserChatInfo chatInfo = new UserChatInfo();

    @Override
    public void parseJson(String s) {
        JSONObject jsonObject = getJsonObject(s);

        // 基础信息
        if (!jsonObject.isNull("user_base")) {
            String json = jsonObject.optString("user_base");
            super.parseBasic(json);
        }

        // 详细信息
        if (!jsonObject.isNull("user_detail")) {
            String json = jsonObject.optString("user_detail");
            super.parseJson(json);
        }

        // 用户相册
        if (!jsonObject.isNull("rec_user_photo")) {
            this.userPhotos = (List<UserPhoto>) getBaseDataList(jsonObject.optJSONArray("rec_user_photo"), UserPhoto.class);
        }

        // 用户视频集
        if (!jsonObject.isNull("rec_user_video")) {
            this.userVideos = (List<UserVideo>) getBaseDataList(jsonObject.optJSONArray("rec_user_video"), UserVideo.class);
        }
    }

    public UserChatInfo getChatInfo() {
        return chatInfo;
    }

    public List<UserVideo> getUserVideos() {
        return userVideos;
    }

    public List<UserPhoto> getUserPhotos() {
        return userPhotos;
    }

    public int getDiamondsSum() {
        return PSP.getInstance().getInt("diamondsSum" + getUid(), 0);
    }

    public void setDiamondsSum(int diamondsSum) {
        PSP.getInstance().put("diamondsSum" + getUid(), diamondsSum);
    }

    public UserDetail() {
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(this.userPhotos);
        dest.writeTypedList(this.userVideos);
        dest.writeParcelable(this.chatInfo, flags);
    }

    protected UserDetail(Parcel in) {
        this.userPhotos = in.createTypedArrayList(UserPhoto.CREATOR);
        this.userVideos = in.createTypedArrayList(UserVideo.CREATOR);
        this.chatInfo = in.readParcelable(UserChatInfo.class.getClassLoader());
    }

    public static final Creator<UserDetail> CREATOR = new Creator<UserDetail>() {
        @Override
        public UserDetail createFromParcel(Parcel source) {
            return new UserDetail(source);
        }

        @Override
        public UserDetail[] newArray(int size) {
            return new UserDetail[size];
        }
    };
}
